var datas=[];
function alltypepageing(url,sear) {
    var adata = {
        name : sear,
        pagesize : 999,
        pagenumber : 1
    };
    $.ajax({
        type : "GET",
        data : adata,
        dataType : "json",
        url : url,
        success : function(json) {
            datas = json.records;
            var bmiMan=[0,0,0,0];
            var bmiWoman=[0,0,0,0];
            var bmiHaveIll=[0,0,0,0];
            var bmiNoIll=[0,0,0,0];
            for (var i=0;i<datas.length;i++){
                if (datas[i].sex=="男"){

                    if (datas[i].bmi<"18"){
                        bmiMan[0]+=1;
                        if (datas[i].nxgbhistory=="有"){
                            bmiHaveIll[0]+=1;
                        } else {
                            bmiNoIll[0]+=1;
                        }
                    }else if (datas[i].bmi<"23") {
                        bmiMan[1]+=1;
                        if (datas[i].nxgbhistory=="有"){
                            bmiHaveIll[1]+=1;
                        } else {
                            bmiNoIll[1]+=1;
                        }
                    }else if (datas[i].bmi<"27") {
                        bmiMan[2]+=1;
                        if (datas[i].nxgbhistory=="有"){
                            bmiHaveIll[2]+=1;
                        } else {
                            bmiNoIll[2]+=1;
                        }
                    } else {
                        bmiMan[3]+=1;
                        if (datas[i].nxgbhistory=="有"){
                            bmiHaveIll[3]+=1;
                        } else {
                            bmiNoIll[3]+=1;
                        }
                    }

                } else if (datas[i].sex=="女") {

                    if (datas[i].bmi<"18"){
                        bmiWoman[0]+=1;
                        if (datas[i].nxgbhistory=="有"){
                            bmiHaveIll[0]+=1;
                        } else {
                            bmiNoIll[0]+=1;
                        }
                    }else if (datas[i].bmi<"23") {
                        bmiWoman[1]+=1;
                        if (datas[i].nxgbhistory=="有"){
                            bmiHaveIll[1]+=1;
                        } else {
                            bmiNoIll[1]+=1;
                        }
                    }else if (datas[i].bmi<"27") {
                        bmiWoman[2]+=1;
                        if (datas[i].nxgbhistory=="有"){
                            bmiHaveIll[2]+=1;
                        } else {
                            bmiNoIll[2]+=1;
                        }
                    } else {
                        bmiWoman[3]+=1;
                        if (datas[i].nxgbhistory=="有"){
                            bmiHaveIll[3]+=1;
                        } else {
                            bmiNoIll[3]+=1;
                        }
                    }

                }

            }

            var dom = document.getElementById("container");
            var myChart = echarts.init(dom);
            var option = {
                title : {
                    text: 'BMI性别统计折线图',
                },
                tooltip : {
                    trigger: 'axis'
                },
                legend: {
                    data:['男','女']
                },
                toolbox: {
                    show : true,
                    feature : {
                        dataView : {show: true, readOnly: false},
                        restore : {show: true},
                        saveAsImage : {show: true}
                    }
                },
                calculable : true,
                xAxis : [
                    {
                        type : 'category',
                        data : ['<=18','18-23','23-27','>=27']
                    }
                ],
                yAxis : [
                    {
                        type : 'value'
                    }
                ],
                series : [
                    {
                        name:'男',
                        type:'line',
                        data:bmiMan
                    },
                    {
                        name:'女',
                        type:'line',
                        data:bmiWoman
                    }
                ]
            };
            myChart.setOption(option);

            var dom2 = document.getElementById("container2");
            var myChart2 = echarts.init(dom2);
            var option2 = {
                title : {
                    text: 'BMI与性别统计柱状图',
                },
                tooltip : {
                    trigger: 'axis'
                },
                legend: {
                    data:['男','女']
                },
                toolbox: {
                    show : true,
                    feature : {
                        dataView : {show: true, readOnly: false},
                        restore : {show: true},
                        saveAsImage : {show: true}
                    }
                },
                calculable : true,
                xAxis : [
                    {
                        type : 'category',
                        data : ['BMI <=18','BMI 18-23','BMI 23-27','BMI >=27']
                    }
                ],
                yAxis : [
                    {
                        type : 'value'
                    }
                ],
                series : [
                    {
                        name:'男',
                        type:'bar',
                        data:bmiMan
                    },
                    {
                        name:'女',
                        type:'bar',
                        data:bmiWoman
                    }
                ]
            };
            myChart2.setOption(option2);

            var dom3 = document.getElementById("container3");
            var myChart3 = echarts.init(dom3);
            var option3 = {
                title:{
                    text:'BMI占比统计'
                },
                tooltip : {
                    trigger: 'item',
                    formatter: "BMI占比统计 <br/>{b} : {d}%"
                },
                series:[{
                    type:'pie',
                    radius:'60%',
                    data:[
                        {value:bmiMan[0]+bmiWoman[0],name:'<=18'},
                        {value:bmiMan[1]+bmiWoman[1],name:'18-23'},
                        {value:bmiMan[2]+bmiWoman[2],name:'23-27'},
                        {value:bmiMan[3]+bmiWoman[3],name:'>=27'}
                    ]
                }]
            };
            myChart3.setOption(option3);


            var dom4 = document.getElementById("container4");
            var myChart4 = echarts.init(dom4);
            var option4 = {
                title:{
                    text:'BMI心脏病史占比统计'
                },
                tooltip : {
                    trigger: 'item',
                    formatter: "BMI心脏病史占比统计 <br/>{b} : {d}%"
                },
                series:[{
                    type:'pie',
                    radius:'60%',
                    data:[
                        {value:bmiHaveIll[0],name:'BMI <=18 且有病史'},
                        {value:bmiHaveIll[1],name:'BMI 18-23 且有病史'},
                        {value:bmiHaveIll[2],name:'BMI 23-27 且有病史'},
                        {value:bmiHaveIll[3],name:'BMI >=27 且有病史'},
                        {value:bmiNoIll[0],name:'BMI <=18 且无病史'},
                        {value:bmiNoIll[1],name:'BMI 18-27 且无病史'},
                        {value:bmiNoIll[2],name:'BMI 23-27 且无病史'},
                        {value:bmiNoIll[3],name:'BMI >=27 且无病史'}
                    ]
                }]
            };
            myChart4.setOption(option4);
        }
    });
}

alltypepageing("/Auth/check/findByPage.shtml",null);
